/**
 * @author Pawel Gadecki <pidzama@gmail.com>
 * 
 */
package spwodne;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import org.jdesktop.layout.GroupLayout;

public class OSzukaj extends JFrame {

    public OSzukaj(java.util.List lista) {
        l = lista;
        mts = new MTSzukaj(l, "", "");
        initComponents();
        jTable1.setAutoCreateRowSorter(true);
    }

    private void initComponents() {
        jPanel1 = new JPanel();
        jLabel1 = new JLabel();
        jLabel2 = new JLabel();
        txtImie = new JTextField();
        txtNazwisko = new JTextField();
        jButton1 = new JButton();
        jButton2 = new JButton();
        jScrollPane1 = new JScrollPane();
        jTable1 = new JTable(mts);
        setDefaultCloseOperation(2);
        setTitle("Wyszukiwanie");
        setResizable(false);
        jPanel1.setBorder(BorderFactory.createEtchedBorder());
        jLabel1.setText("Imi\u0119");
        jLabel2.setText("Nazwisko");
        txtImie.setNextFocusableComponent(txtNazwisko);
        txtNazwisko.setNextFocusableComponent(jButton1);
        jButton1.setText("Szukaj");
        jButton1.setNextFocusableComponent(jButton2);
        jButton1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
            final OSzukaj this$0;
            

            {
                this$0 = OSzukaj.this;
            //super();
            }
        });
        jButton2.setText("Zamknij");
        jButton2.setNextFocusableComponent(jTable1);
        jButton2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
            final OSzukaj this$0;
            

            {
                this$0 = OSzukaj.this;
            //super();
            }
        });
        GroupLayout jPanel1Layout = new GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(1).add(jPanel1Layout.createSequentialGroup().addContainerGap().add(jPanel1Layout.createParallelGroup(1).add(jLabel1).add(jLabel2)).add(49, 49, 49).add(jPanel1Layout.createParallelGroup(1, false).add(txtNazwisko).add(txtImie, -1, 179, 32767)).add(23, 23, 23).add(jPanel1Layout.createParallelGroup(1, false).add(jButton2, -1, -1, 32767).add(jButton1, -1, -1, 32767)).addContainerGap(50, 32767)));
        jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(1).add(jPanel1Layout.createSequentialGroup().addContainerGap().add(jPanel1Layout.createParallelGroup(1).add(jPanel1Layout.createSequentialGroup().add(jPanel1Layout.createParallelGroup(3).add(jLabel1).add(txtImie, -2, -1, -2)).addPreferredGap(0).add(jPanel1Layout.createParallelGroup(3).add(jLabel2).add(txtNazwisko, -2, -1, -2))).add(jPanel1Layout.createSequentialGroup().add(jButton1).addPreferredGap(0).add(jButton2))).addContainerGap(-1, 32767)));
        jTable1.addKeyListener(new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent evt) {
                jTable1KeyPressed(evt);
            }
            final OSzukaj this$0;
            

            {
                this$0 = OSzukaj.this;
            //super();
            }
        });
        jTable1.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent evt) {
                jTable1MouseClicked(evt);
            }
            final OSzukaj this$0;
            

            {
                this$0 = OSzukaj.this;
            //super();
            }
        });
        jScrollPane1.setViewportView(jTable1);
        GroupLayout layout = new GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(1).add(layout.createSequentialGroup().addContainerGap().add(layout.createParallelGroup(2, false).add(1, jPanel1, -1, -1, 32767).add(1, jScrollPane1, -1, 453, 32767)).addContainerGap(-1, 32767)));
        layout.setVerticalGroup(layout.createParallelGroup(1).add(layout.createSequentialGroup().addContainerGap().add(jPanel1, -2, -1, -2).add(23, 23, 23).add(jScrollPane1, -2, 133, -2).addContainerGap(18, 32767)));
        pack();
    }

    private void jTable1KeyPressed(KeyEvent evt) {
        label0:
        {
            int nr = jTable1.getSelectedRow();
            int key = evt.getKeyCode();
            KeyEvent _tmp = evt;
            if (key != 10) {
                KeyEvent _tmp1 = evt;
                if (key != 32) {
                    break label0;
                }
            }
            if (nr >= 0) {
                OEKlient oek = new OEKlient((Klient) mts.getLK().get(nr));
                oek.setVisible(true);
            }
        }
    }

    private void jTable1MouseClicked(MouseEvent evt) {
        int nr = jTable1.getSelectedRow();
        if (evt.getClickCount() == 2 && nr >= 0) {
            OEKlient oek = new OEKlient((Klient) mts.getLK().get(nr));
            oek.setVisible(true);
        }
    }

    private void jButton2ActionPerformed(ActionEvent evt) {
        dispose();
    }

    private void jButton1ActionPerformed(ActionEvent evt) {
       // mts = new MTSzukaj(l, txtImie.getText(), txtNazwisko.getText());
        //jTable1.setModel(mts);
        mts.szukaj(txtImie.getText(), txtNazwisko.getText());
    }
    private MTSzukaj mts;
    private java.util.List l;
    private JButton jButton1;
    private JButton jButton2;
    private JLabel jLabel1;
    private JLabel jLabel2;
    private JPanel jPanel1;
    private JScrollPane jScrollPane1;
    private JTable jTable1;
    private JTextField txtImie;
    private JTextField txtNazwisko;
}
